<?php

namespace Chat\Model\Entity;

class ChatMessage {
	
	protected $ID;
	
	protected $senderID;
	
	protected $receiverID;
	
	protected $text;
	
	protected $posted_on;
	
	public function __construct(array $options = null) {
		if (is_array($options)) {
			$this->setOptions($options);
		}
	}
	
	public function setOptions(array $options) {
		$methods = get_class_methods($this);
		foreach ($options as $key => $value) {
			$method = 'set' . ucfirst($key);
			if (in_array($method, $methods)) {
				$this->$method($value);
			}
		}
		return $this;
	}
	
	public function __set($name, $value) {
		$method = 'set' . $name;
		if (!method_exists($this, $method)) {
			throw new Exception('Invalid Method');
		}
		$this->$method($value);
	}
	
	public function __get($name) {
		$method = 'get' . $name;
		if (!method_exists($this, $method)) {
			throw new Exception('Invalid Method');
		}
		return $this->$method();
	}
	
	public function getID(){
		return $this->ID;
	}
	
	
	public function getPosted_on(){
		return $this->posted_on;
	}
	
	public function setText($text){
		$this->text = $text;
		return $this;
	}
	
	public function getText(){
	return $this->text;
	}
	
	public function setReceiverID($userID){
		$this->receiverID = $userID;
		return $this;
	}
	
	public function getReceiverID(){
		return $this->receiverID;
	}
	
	public function setSenderID($userID){
		$this->senderID = $userID;
		return $this;
	}
	
	public function getSenderID(){
		return $this->senderID;
	}
	
	
}